package com.ting.test.algorithms.二叉树;

/**
 * 满二叉树的定义
 * 节点个数==2^height-1
 * <p>
 * 利用递归的思想
 */
public class 判断是满二叉树 {
    public static void main(String[] args) {
        TreeNode head = new TreeNode(2);
        Info info = process(head);
        System.out.println(info.size==(2^info.height-1));
    }

    private static Info process(TreeNode node) {
        //base case
        if (node == null) {
            //默认空节点的高度为0，size==0
            return new Info(0, 0);
        }
        Info leftInfo = process(node.left);
        Info rightInfo = process(node.right);

        int size = leftInfo.size + rightInfo.size + 1;
        int height = Math.max(leftInfo.height, rightInfo.height) + 1;
        return new Info(size, height);
    }


    static class Info {
        int size;
        int height;

        public Info(int size, int height) {
            this.size = size;
            this.height = height;
        }
    }

}
